"""
三种等待方式
1.硬性等待
2.智能等待-隐性等待，只需要设置一次，但是只能等待元素
3.智能等待-显性等待

"""
import time

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions

driver = webdriver.Chrome()
url = "https://www.baidu.com"
driver.get(url)

# 智能等待-隐性等待
# driver.implicitly_wait(2)
elem = driver.find_element('id', 'kw')
# # 显性等待方式
# wait = WebDriverWait(driver, timeout=10, poll_frequency=0.5)
# located = ["id", "kw"]
# # 等待某个元素加载
# wait.until(expected_conditions.presence_of_element_located(located))
# # 等待某个元素出现
# wait.until(expected_conditions.visibility_of_element_located(located))
# # 等待某个元素可以被点击
# wait.until(expected_conditions.element_to_be_clickable(located))
elem.send_keys("浩仔")
elem.submit()

# 硬性等待，强制等待两秒
# time.sleep(2)
# print(driver.title)


#显性等待控制器，传三个参数  driver, 等待时间， 循环时间
wait = WebDriverWait(driver, timeout=10, poll_frequency=0.5)
#等待直到XX出现为止 10S内 每隔0.5秒看一次标题有没有浩仔
wait.until(expected_conditions.title_contains("浩仔"))

print(driver.title)
driver.quit()


